package com.typhosoft.jcommon.network;

import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;

import java.io.IOException;

/**
 * Created by Mario on 21/03/2014.
 */
public class CServer {
    Server server;

    public CServer(Listener... listeners) throws IOException {
        server = new Server() {
            protected Connection newConnection() {
                // By providing our own connection implementation, we can store per
                // connection state without a connection ID to state look up.
                return new MyConnection();
            }
        };

        // For consistency, the classes to be sent over the network are
        // registered by the same method for both the client and server.
        CNetwork.register(server);
        for (Listener listener : listeners) {
            server.addListener(listener);
        }
        server.bind(CNetwork.port);
        server.start();
    }

    // This holds per connection state.
    static class MyConnection extends Connection {
        public String name;
    }
}
